package com.musiklegal;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

class AnAdapter extends BaseAdapter
{
	String title;
	List<DataSong> data;
	Activity act;
	LayoutInflater inflater;
	AnAdapter(Activity a,List<DataSong> sdata,String nama)
	{
		title = nama;
		act = a;
		data= sdata;
		inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	static class ViewHolder
	{
		ImageView img;
		TextView judul,artist;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
        ViewHolder holder;
        if(convertView==null)
        {
            vi = inflater.inflate(R.layout.view, null);
            holder=new ViewHolder();
            holder.judul=(TextView)vi.findViewById(R.id.TextView01);
            holder.artist=(TextView)vi.findViewById(R.id.TextView02);
            holder.img=(ImageView)vi.findViewById(R.id.ImageView01);
            vi.setTag(holder);
        }
        else
            holder=(ViewHolder)vi.getTag();
        
        holder.judul.setText(data.get(position).song);
        holder.artist.setText(data.get(position).artist);
        holder.img.setTag(data.get(position).album);
        
        return vi;
	}
}